import { GSlider } from "../../../../com/mui/controls/GSlider";
import { IClean } from "../../../../com/gengine/core/IClean";
import { LayerManager } from "../../manager/LayerManager";
import { Tooltip } from "../common/tooltip/Tooltip";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Global } from "../../../../com/gengine/global/Global";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class ControlSlider
    
    export  class ControlSlider extends GSlider implements IClean
    {
        constructor(arg1: string, arg2: string)
        {
            super();
            this._name = arg2;
            this._thubmName = arg1;
            this.init();
            return;
        }

        /* internal  */addOrRemoveLabelToolTip(arg1: Boolean=false): void
        {
            if (this._labelTip) 
            {
                if (arg1) 
                {
                    LayerManager.toolTipLayer.addChild(this._labelTip);
                }
                else if (this._labelTip.parent) 
                {
                    this._labelTip.parent.removeChild(this._labelTip);
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            this._labelTip = new Tooltip();
            this._labelTip.mouseEnabled = false;
            this._labelTip.mouseChildren = false;
            this._thumbSprite = new Object /* flash.display.Sprite */();
            this._thumbBitmap = GlobalClass.getBitmap(this._thubmName);
            this._thumbSprite.graphics.beginFill(16777215, 0);
            this._thumbSprite.graphics.drawRect(0, 0, 13, 13);
            this._thumbSprite.addChild(this._thumbBitmap);
            this._thumbSprite.buttonMode = true;
            this._thumbSprite.useHandCursor = true;
            this._thumbSprite.cacheAsBitmap = true;
            this.setStyle("sliderTrackSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("sliderTrackDisabledSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("thumbDisabledSkin", this._thumbSprite);
            this.setStyle("thumbDownSkin", this._thumbSprite);
            this.setStyle("thumbOverSkin", this._thumbSprite);
            this.setStyle("thumbUpSkin", this._thumbSprite);
            this.width = 100;
            this.height = 10;
            this.maximum = 100;
            this.minimum = 0;
            this.value = 50;
            this.snapInterval = 1;
            this.liveDragging = true;
            this.mouseEnabled = true;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.thumb.addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onThumbRollOver);
            this.thumb.addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onThumbRollOut);
            this.thumb.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onThumbMouseDown);
            return;
        }

        public get thumbData(): string
        {
            return this._thumbData;
        }

        public set thumbData(arg1: string)
        {
            this._thumbData = arg1;
            return;
        }

        public get sliderData(): string
        {
            return this._sliderData;
        }

        public set sliderData(arg1: string)
        {
            this._sliderData = arg1;
            return;
        }

        /* internal  */onThumbRollOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isOver = true;
            this.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrame);
            return;
        }

        public onStateMouseUp(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isDown = false;
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStateMouseUp);
            Dispatcher.dispatchEvent(new DataEvent(EventName.HeaderSliderUp, this._name));
            return;
        }

        /* internal  */onThumbMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onStateMouseUp);
            this._isDown = true;
            this.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrame);
            return;
        }

        /* internal  */onThumbMouseMove(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.thumbData != "") 
            {
                this.addOrRemoveLabelToolTip(true);
                this._labelTip.data = this.thumbData;
                this._labelTip.x = arg1.stageX + 15;
                this._labelTip.y = arg1.stageY + 15;
            }
            return;
        }

        /* internal  */onEnterFrame(arg1: Object /* flash.events.Event */): void
        {
            if (this.thumbData != "") 
            {
                if (this._isOver || this._isDown) 
                {
                    this.addOrRemoveLabelToolTip(true);
                }
                else 
                {
                    this.addOrRemoveLabelToolTip(false);
                    this.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrame);
                }
                this._labelTip.data = this.thumbData;
                this._labelTip.x = this.getX();
                this._labelTip.y = this.localToGlobal(new Object /* flash.geom.Point */(0, 0)).y + 15;
            }
            return;
        }

        public getX(): number
        {
            var loc1=this.localToGlobal(new Object /* flash.geom.Point */(0, 0)).x + 15;
            var loc2=loc1 + this.width;
            var loc3=Global.stage.mouseX + 15;
            loc3 = loc3 > loc1 ? loc3 : loc1;
            loc3 = loc3 < loc2 ? loc3 : loc2;
            return loc3;
        }

        /* internal  */onThumbRollOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isOver = false;
            return;
        }

        public get isDown(): Boolean
        {
            return this._isDown;
        }

        public set thubmName(arg1: string)
        {
            this._thubmName = arg1;
            this._thumbBitmap.bitmapData = GlobalClass.getBitmapData(arg1);
            return;
        }

        public get thumbSprite(): Object /* flash.display.Sprite */
        {
            return this._thumbSprite;
        }

        public showtips(): void
        {
            if (this.thumbData != "") 
            {
                this.addOrRemoveLabelToolTip(true);
                this._labelTip.data = this.thumbData;
                this._labelTip.x = this.getX();
                this._labelTip.y = this.localToGlobal(new Object /* flash.geom.Point */(0, 0)).y + 30;
            }
            return;
        }

        public hidetips(): void
        {
            if (!this._isOver && !this._isDown) 
            {
                this.addOrRemoveLabelToolTip(false);
            }
            return;
        }

        public clean(): void
        {
            this.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrame);
            this.addOrRemoveLabelToolTip(false);
            return;
        }

        /* internal */ /* var */_thubmName: string;

        /* internal */ /* var */_thumbData: string="";

        /* internal */ /* var */_sliderData: string="";

        /* internal */ /* var */_labelTip: Tooltip;

        /* internal */ /* var */_thumbSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_thumbBitmap: Object /* flash.display.Bitmap */;

        public /* var */_isDown: Boolean=false;

        public /* var */_isOver: Boolean=false;

        public /* var */_name: string;
    }
